# -*-coding:utf-8
# ProjectName: smalleel-api-tools
# FileName: logUtil.py
# @Time :2022/8/29 09:32
# @Author :
# @Description:日志

import os

from loguru import logger

from common.util.configUtil.configUtil import ConfigUtil
from common.util.timeUntil.timeUtil import get_nowtime


class LoggerUtil:
    def __init__(self, option: str):
        self.readIni = ConfigUtil()
        logPath = self.readIni.get_log_path(option)
        name = os.path.join(logPath, f"{option}-{get_nowtime(4)}.log")
        logger.remove(handler_id=None)
        # 日志超过50M压缩成zip格式
        logger.add(name, retention="7 days", rotation="50MB", enqueue=True, encoding='utf-8', compression="zip")

    @staticmethod
    def info(msg: str) -> None:
        """打印 info 级别的日志"""
        logger.info(msg)

    @staticmethod
    def debug(msg: str) -> None:
        """打印 debug 级别的日志"""
        logger.debug(msg)

    @staticmethod
    def warning(msg: str) -> None:
        """打印 warning 级别的日志"""
        logger.warning(msg)

    @staticmethod
    def error(msg: str) -> None:
        """打印 error 级别的日志"""
        logger.error(msg)


if __name__ == '__main__':
    log = LoggerUtil("web_log_path")
